package com.eudon.design_pattern.creational.prototype;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author eudon
 * @description 用户信息
 * @date 2025/9/1
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class UserInfo implements MayCopy {
    private String name;
    private String gender;
    private Integer age;
    private List<String> addresses;
    private Map<String, String> schools;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public List<String> getAddresses() {
        return addresses;
    }

    public void setAddresses(List<String> addresses) {
        this.addresses = addresses;
    }

    public Map<String, String> getSchools() {
        return schools;
    }

    public void setSchools(Map<String, String> schools) {
        this.schools = schools;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        UserInfo clone = (UserInfo) super.clone();
        //需要注意：此处的便利clone是为了深度拷贝其引用内容，如果引用内容很复杂，需要修改这里的clone逻辑
        clone.addresses = (List<String>) new ArrayList<String>(clone.getAddresses()).clone();

        clone.schools = clone.getSchools().entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        return clone;
    }
}
